import { createRouter, createWebHistory } from "vue-router";
import IndexView from "../views/index.vue";
import LoginView from "../views/login/index.vue"; // 登录页面
import ForgetPassword from "../views/login/forgetPassword.vue";
import RegisteredView from "../views/login/registered.vue";
import HomeView from "../views/indexView/index.vue";
import MyProject from "../views/project/myProject.vue";
import JudgeProject from "../views/project/judgeProject.vue";
import Detail from "../views/project/detail.vue";
import JudgeDetail from "../views/project/judgedetail.vue";
import CompanyInfo from "../views/project/companyInfo.vue";
import JudgeInfo from "../views/project/judgeInfo.vue";
import EditCompanyInfo from "../views/project/editCompanyInfo.vue";
import AnnouncementSearch from "../views/announcement/search.vue";
import AnnouncementDetail from "../views/announcement/detail.vue";
import AnnouncementApply from "../views/announcement/apply.vue";
import Help from "../views/helpCenter/index.vue";
import HelpDetail from "../views/helpCenter/detail.vue";
import ProjectNotice from "../views/projectNotice/index.vue";
const routes = [
  {
    path: "/home",
    component: IndexView,
    name: "home",
    meta: { keepAlive: true }, // 开启页面缓存
  },
  // 默认重定向到登录页面
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/login",
    component: LoginView,
    name: "login",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/forget",
    component: ForgetPassword,
    name: "forget",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/registered",
    component: RegisteredView,
    name: "registered",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/index",
    component: HomeView,
    name: "index",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/myProject",
    component: MyProject,
    name: "myProject",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/judgeProject",
    component: JudgeProject,
    name: "judgeProject",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/detail",
    component: Detail,
    name: "detail",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/judgedetail",
    component: JudgeDetail,
    name: "judgedetail",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/companyInfo",
    component: CompanyInfo,
    name: "companyInfo",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/judgeInfo",
    component: JudgeInfo,
    name: "judgeInfo",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/editCompanyInfo",
    component: EditCompanyInfo,
    name: "editCompanyInfo",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/search",
    component: AnnouncementSearch,
    name: "search",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/announcementDetail",
    component: AnnouncementDetail,
    name: "announcementDetail",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/announcementApply",
    component: AnnouncementApply,
    name: "announcementApply",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/help",
    component: Help,
    name: "help",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/helpDetail",
    component: HelpDetail,
    name: "helpDetail",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
  {
    path: "/projectNotice",
    component: ProjectNotice,
    name: "projectNotice",
    meta: { keepAlive: false }, // 登录页面无需缓存
  },
];

const router = createRouter({ history: createWebHistory(), routes });

router.beforeEach((to, from, next) => {
  // 如果需要登录校验逻辑，可以启用以下代码
  // const token = localStorage.getItem("auth_token");
  // if (!token && to.path !== "/login") {
  //   next("/login"); // 如果用户没有登录，强制跳转到登录页
  // } else {
  next(); // 允许导航
  // }
});

export default router;
